import Vue from 'vue'

export const appid = process.env.NODE_ENV === 'production' ? 'wx6ee00daf1a7feafc' : 'wx6a78cee495003328'
// export const appid = 'wx956c51fbb4feab34' // 'wx6a78cee495003328'
export const url = process.env.NODE_ENV === 'production' ? 'https://zanshang520.com' : 'https://test.zanshang520.com'
// export const url = 'https://test.zanshang520.com'
export const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=snsapi#wechat_redirect `

export async function requestApi (u, method, queryString, param) {
  // console.log(Vue.http, method)
  let body = ''
  if (method === 'post') body = param
  const res = await Vue.http[method](`${u}?${queryString}`, body)
  if (res.body.status) {
    console.log(u, res.body.data)
    return res.body.data
  } else {
    throw new Error(res.body.msg)
  }
}

export function dateFormat (t) {
  let time = new Date(t)
  let [yy, mm, dd, hh, ss, mmm] = [time.getFullYear(), time.getMonth() + 1, time.getDate(), time.getHours(), time.getMinutes(), time.getSeconds()]
  if (mm < 10) mm = '0' + mm
  if (dd < 10) dd = '0' + dd
  if (hh < 10) hh = '0' + hh
  if (ss < 10) ss = '0' + ss
  if (mmm < 10) mmm = '0' + mmm
  return `${yy}-${mm}-${dd} ${hh}:${ss}:${mmm}`
}
